home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / COP.ZIP / RECTPIE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-21  |  5.3 KB  |  241 lines

  1. #include "rectpie.h"
  2.  
  3.  
  4. /*  Rectangle  */
  5.  
  6. polyBaseThiS_0_def(RT,Shape,Rectangle)
  7.  
  8. vFt_def(Rectangle,Shape)  =  {
  9.     vF_value(RT,SH,show),
  10.     vF_value(RT,SH,destruct)
  11. };
  12.  
  13. vf_def(void,RT,SH,show,(Shape * thiS, int xxpose,
  14.     int yxpose, unsigned scale))
  15. {
  16.     Rectangle * RTthiS = SH_RectangleThiS(thiS);
  17.     int poly[10];
  18.     int dw = (int)(RTthiS->width/2*scale);
  19.     int dh = (int)(RTthiS->heighth/2*scale);
  20. /*lint -e506 */
  21.     int l  = (int)RT_getx(RTthiS)+xxpose - dw;
  22.     int t  = (int)RT_gety(RTthiS)+yxpose - dh;
  23.     int r  = (int)RT_getx(RTthiS)+xxpose + dw;
  24.     int b  = (int)RT_gety(RTthiS)+yxpose + dh;
  25. /*lint +e506 */
  26.     poly[0] = l;  poly[1] =  t;
  27.     poly[2] = r;  poly[3] =  t;
  28.     poly[4] = r;  poly[5] =  b;
  29.     poly[6] = l;  poly[7] =  b;
  30.     poly[8] = l;  poly[9] =  t;
  31.  
  32.     drawpoly(5,poly);
  33. }
  34.  
  35. vf_def(void,RT,SH,destruct,(Shape * thiS,
  36.     unsigned nobj, int malloced))
  37. {
  38.     struct_destruct(RT,SH_RectangleThiS(thiS),
  39.         nobj,malloced);
  40. }
  41.  
  42. struct_initVFTs_def(RT,(Rectangle * thiS,
  43.     void * descendanT_0
  44.     , vFT_0_decl(Shape)))
  45. {
  46.     poly_assign(thiS,descendanT_0);
  47.     struct_initVFTs(SH,
  48.         (RT_ShapeThiS(thiS), (void *) thiS,
  49.         vFT_0_name(Shape)));
  50. }
  51.  
  52. struct_init_def(Rectangle,RT,_,
  53.     (Rectangle * thiS_0, unsigned nobj,
  54.         unsigned width, unsigned heighth,
  55.         unsigned x, unsigned y))
  56. {
  57.   unsigned i, fail;
  58.   int malloced = 0;
  59.  
  60.   if (!nobj)
  61.     return (Rectangle *)0;
  62.   if (!thiS_0) if ((thiS_0 = (Rectangle *)
  63.     RT_malloc(nobj))
  64.     == (Rectangle *)0)
  65.     return (Rectangle *)0;
  66.   else
  67.     malloced = 1;
  68.   for (i = fail = 0; i < nobj; i++)  {
  69.     if (!struct_init(SH,_,(RT_ShapeThiS(&thiS_0[i]),
  70.       1,(x?x:width/2),(y?y:heighth/2))))  {
  71.       fail = 1;
  72.       break;
  73.     }
  74.     struct_initVFTs(RT,(&thiS_0[i], (void *)0,
  75.       vFT_value(Rectangle,Shape)));
  76.  
  77.     thiS_0[i].width = width;
  78.     thiS_0[i].heighth = heighth;
  79.  
  80.   }  /* for */
  81.  
  82.   if (fail)  {
  83.     /*
  84.     All indices >= "i" have already been destructed
  85.     as required.  Indices i-1 to 0 are now
  86.     destructed via the destructor since we're
  87.     inside the constructor of the instance level if
  88.     i > 0.  Remember that if this is an
  89.     intermediate constructor call that i == 0
  90.     and malloced == 0 always so no further
  91.     processing is required at this level and NULL
  92.     is returned to the calling level constructor.
  93.     */
  94.     if (i)
  95.       struct_destruct(RT,thiS_0,i,malloced);
  96.     else if (malloced)
  97.       RT_free(thiS_0);
  98.     return (Rectangle *) 0;
  99.   }
  100.  
  101.   return thiS_0;
  102. }
  103.  
  104. struct_destruct_def(Rectangle,RT)
  105. {
  106.   unsigned i;
  107.  
  108.   if (!thiS_0 || !nobj)
  109.     return;
  110.  
  111.   for (i = nobj; i--; /* no reinit */)  {
  112.  
  113.     struct_initVFTs(RT,(&thiS_0[i], (void *)0,
  114.       vFT_value(Rectangle,Shape)));
  115.  
  116.     struct_destruct(SH,RT_ShapeThiS(&thiS_0[i]),1,0);
  117.  
  118.   }
  119.  
  120.   if (malloced)
  121.     RT_free(thiS_0);
  122. }
  123.  
  124.  
  125. /*  PieSlice  */
  126.  
  127. polyBaseThiS_0_def(PS,Shape,PieSlice)
  128.  
  129. vFt_def(PieSlice,Shape)  =  {
  130.     vF_value(PS,SH,show),
  131.     vF_value(PS,SH,destruct)
  132. };
  133.  
  134. vf_def(void,PS,SH,show,(Shape * thiS, int xxpose,
  135.     int yxpose, unsigned scale))
  136. {
  137.     PieSlice * PSthiS = SH_PieSliceThiS(thiS);
  138.  
  139. /*lint -e506 */
  140.     pieslice((int)PS_getx(PSthiS)+xxpose,
  141.         (int)PS_gety(PSthiS)+yxpose,
  142.         (int)PSthiS->startAngle,
  143.         (int)PSthiS->endAngle,
  144.         (int)(PS_CircleThiS(PSthiS)
  145.             ->radius*scale));
  146. /*lint +e506 */
  147.     /* radius is in Circle protected scope so it
  148.        is accessible from PieSlice */
  149. }
  150.  
  151. vf_def(void,PS,SH,destruct,(Shape * thiS,
  152.     unsigned nobj, int malloced))
  153. {
  154.     struct_destruct(PS,SH_PieSliceThiS(thiS),
  155.         nobj,malloced);
  156. }
  157.  
  158. struct_initVFTs_def(PS,(PieSlice * thiS,
  159.     void * descendanT_0
  160.     , vFT_0_decl(Shape)))
  161. {
  162.     poly_assign(thiS,descendanT_0);
  163.     struct_initVFTs(CR,
  164.         (PS_CircleThiS(thiS), (void *) thiS,
  165.         vFT_0_name(Shape)));
  166. }
  167.  
  168. struct_init_def(PieSlice,PS,_,
  169.     (PieSlice * thiS_0, unsigned nobj,
  170.         unsigned startAngle,
  171.         unsigned endAngle,
  172.         unsigned radius,
  173.         unsigned x, unsigned y))
  174. {
  175.   unsigned i, fail;
  176.   int malloced = 0;
  177.  
  178.   if (!nobj)
  179.     return (PieSlice *)0;
  180.   if (!thiS_0) if ((thiS_0 = (PieSlice *)
  181.     PS_malloc(nobj))
  182.     == (PieSlice *)0)
  183.     return (PieSlice *)0;
  184.   else
  185.     malloced = 1;
  186.   for (i = fail = 0; i < nobj; i++)  {
  187.     if (!struct_init(CR,_,(PS_CircleThiS(&thiS_0[i]),
  188.       1,radius,x,y)))  {
  189.       fail = 1;
  190.       break;
  191.     }
  192.     struct_initVFTs(PS,(&thiS_0[i], (void *)0,
  193.       vFT_value(PieSlice,Shape)));
  194.  
  195.     thiS_0[i].startAngle = startAngle;
  196.     thiS_0[i].endAngle = endAngle;
  197.  
  198.   }  /* for */
  199.  
  200.   if (fail)  {
  201.     /*
  202.     All indices >= "i" have already been destructed
  203.     as required.  Indices i-1 to 0 are now
  204.     destructed via the destructor since we're
  205.     inside the constructor of the instance level if
  206.     i > 0.  Remember that if this is an
  207.     intermediate constructor call that i == 0
  208.     and malloced == 0 always so no further
  209.     processing is required at this level and NULL
  210.     is returned to the calling level constructor.
  211.     */
  212.     if (i)
  213.       struct_destruct(PS,thiS_0,i,malloced);
  214.     else if (malloced)
  215.       PS_free(thiS_0);
  216.     return (PieSlice *) 0;
  217.   }
  218.  
  219.   return thiS_0;
  220. }
  221.  
  222. struct_destruct_def(PieSlice,PS)
  223. {
  224.   unsigned i;
  225.  
  226.   if (!thiS_0 || !nobj)
  227.     return;
  228.  
  229.   for (i = nobj; i--; /* no reinit */)  {
  230.  
  231.     struct_initVFTs(PS,(&thiS_0[i], (void *)0,
  232.       vFT_value(PieSlice,Shape)));
  233.  
  234.     struct_destruct(CR,PS_CircleThiS(&thiS_0[i]),1,0);
  235.  
  236.   }
  237.  
  238.   if (malloced)
  239.     PS_free(thiS_0);
  240. }
  241.